package models

import (
	"time"
)

type User struct {
	Id            int    `xorm:"not null pk autoincr INTEGER"`
	Name          string `xorm:"VARCHAR(20)"`
	Avatar        string `xorm:"VARCHAR(100)"`
	Gender        int    `xorm:"not null default 1 INTEGER"`
	Ctime         int    `xorm:"not null default 0 INTEGER"`
	Email         string `xorm:"VARCHAR(40)" form:"email"`
	Phone         string `xorm:"not null default '''::character varying' VARCHAR(20)"`
	Pwd           string `xorm:"VARCHAR(32)"`
	SubdistrictId int    `xorm:"not null INTEGER"`
}

type WxOpenID struct {
	Id           int    `xorm:"not null pk autoincr INTEGER"`
	Openid       string `xorm:"VARCHAR(100)"`
	Unregistered int    `xorm:"not null default 1 INTEGER"`
	UserId       int    `xorm:"not null default 0 INTEGER"`
	Src          string `xorm:"null  VARCHAR(10)"`
}

type District struct {
	Id       int    `xorm:"not null pk autoincr INTEGER"`
	Province string `xorm:"not null default '''::character varying' VARCHAR(30)"`
	City     string `xorm:"not null default '''::character varying' VARCHAR(30)"`
	District string `xorm:"not null default '''::character varying' VARCHAR(30)"`
}
type Subdistrict struct {
	Id         int    `xorm:"not null pk autoincr INTEGER"`
	DistrictId int    `xorm:"not null INTEGER"`
	Name       string `xorm:"null VARCHAR(30)"`
	Memo       string `xorm:"null VARCHAR(30)"`
}

type Address struct {
	Id     int    `xorm:"not null pk autoincr INTEGER" json:"id"`
	Title  string `xorm:"VARCHAR(30)" json:"title"`
	UserId int    `xorm:"not null INTEGER" json:"-"`
	Room   string `xorm:"VARCHAR(60)" json:"room"`
	Phone  string `xorm:"VARCHAR(11)" json:"phone"`

	Flag          bool `xorm:" default false BOOLEAN" json:"flag"`        //主地址
	SubdistrictId int  `xorm:"not null default 0 INTEGER" json:"subd_id"` // 小区id
}

type Staff struct {
	Id       int    `xorm:"not null pk autoincr INTEGER"`
	Username string `xorm:"not null default '''::character varying' unique VARCHAR(15)"`
	Title    string `xorm:"VARCHAR(10)"`
	Phone    string `xorm:"VARCHAR(20)"`
	Email    string `xorm:"not null default '''::character varying' VARCHAR(40)"`
	Pwd      string `xorm:"not null default '''::character varying' VARCHAR(32)"`
	UserId   int    `xorm:"not null unique INTEGER"`
}

type Department struct {
	Id        int    `xorm:"not null pk autoincr INTEGER"`
	Name      string `xorm:"not null default '''::character varying' unique VARCHAR(20)"`
	IsAllied  bool   `xorm:"not null BOOLEAN"`
	Intro     string `xorm:"VARCHAR(255)"`
	Active    bool   `xorm:"not null default false BOOL"`
	Ctime     int64  `xorm:"not null default 0 BIGINT"`
	Ktime     int64  `xorm:"not null default 0 BIGINT"`
	Wkey      string `xorm:"VARCHAR(32)"`
	Phone     string `xorm:"not null default '''::character varying' VARCHAR(20)"`
	Address   string `xorm:"not null default '''::character varying' VARCHAR(100)"`
	PrinterId int    `xorm:"null INTEGER" form:"printer_id"`
}

type DepStaff struct {
	Id           int `xorm:"not null pk autoincr INTEGER"`
	StaffId      int `xorm:"not null INTEGER"`
	DepartmentId int `xorm:"not null INTEGER"`
	Role         int `xorm:"not null default 8 SMALLINT"`
}

type Printer struct {
	Id       int    `xorm:"not null pk autoincr INTEGER"`
	Key      string `xorm:"not null default '''::character varying' VARCHAR(20)"`
	Sn       string `xorm:"not null default '''::character varying' VARCHAR(20)"`
	Ip       string `xorm:"not null default '''::character varying' VARCHAR(50)"`
	Location string `xorm:"not null default '''::character varying' VARCHAR(30)"`
}

type Warehouse struct {
	Id      int       `xorm:"not null pk autoincr INTEGER"`
	Name    string    `xorm:"not null default '''::character varying' unique VARCHAR(20)"`
	Created time.Time `xorm:"not null TIMESTAMPZ"`
	Updated time.Time `xorm:"not null TIMESTAMPZ"`

	DepartmentId    int `xorm:"not null INTEGER"`
	DistrictId      int `xorm:"not null INTEGER"`
	DeliveryFeeType int `xorm:"not null default 1 SMALLINT"`
}

type Commodity struct {
	Id            int    `xorm:"not null pk autoincr INTEGER"`
	Name          string `xorm:"VARCHAR(20)"`
	ClassCode     string `xorm:"VARCHAR(4)"`
	Intro         int    `xorm:"not null default 0 INTEGER"`
	Price         int    `xorm:"not null default 0 INTEGER"`
	IsOnline      bool   `xorm:"not null default false BOOL"`
	Specification string `xorm:"null VARCHAR(50)"`
	// 团购相关仅仅出现在团购管理页面
	OrderStart          time.Time `xorm:` // 团购开始预订时间
	OrderExpire         time.Time ``      // 团购结束预订时间
	DeliveryStart       time.Time ``      // 团购开始配货时间
	LatestStockingPrice int       ``      //最新进货价
	SupplierId          int       ``      // 主供应商
	SupplierPrinterId   int       ``      // 按供应商要求出单的云打印机id
}

type Barcode struct {
	Id          int    `xorm:"not null pk autoincr INTEGER"`
	Code        string `xorm:"not null VARCHAR(30)"`
	CommodityId int    `xorm:"not null INTEGER"`
}

type CommodityClass struct {
	Id            int    `xorm:"not null pk autoincr INTEGER"`
	Code          string `xorm:"VARCHAR(2)"`
	Name          string `xorm:"VARCHAR(30)"`
	Weight        int    `xorm:"not null default 3 INTEGER"`
	Color         string `xorm:"not null default '''::character varying' VARCHAR(10)"`
	VisibleOnLine int    `xorm:"not null default 1 SMALLINT"`
	ImageId       int    `xorm:"INTEGER"`
}

type CommoditySubclass struct {
	Id            int    `xorm:"not null pk autoincr INTEGER"`
	Code          string `xorm:"VARCHAR(2)"`
	Name          string `xorm:"VARCHAR(30)"`
	Weight        int    `xorm:"not null default 3 INTEGER"`
	VisibleOnLine int    `xorm:"not null default 1 SMALLINT"`
}

type File struct {
	Id           int       `xorm:"not null pk autoincr INTEGER"`
	Name         string    `xorm:"VARCHAR(20)"`
	Created      time.Time `xorm:"not null TIMESTAMPZ"`
	Updated      time.Time `xorm:"not null TIMESTAMPZ"`
	FileTypeId   int       `xorm:"not null INTEGER"`
	Suffix       string    `xorm:"not null default '''::character varying' VARCHAR(255)"`
	FileAccessId int       `xorm:"not null INTEGER"`
}

type FileAccess struct {
	Id   int    `xorm:"not null pk autoincr INTEGER"`
	Name string `xorm:"VARCHAR(20)"`
}

type FileType struct {
	Id   int    `xorm:"not null pk autoincr INTEGER"`
	Name string `xorm:"VARCHAR(20)"`
}

type WSDF struct {
	Id            int `xorm:"not null pk autoincr INTEGER"`
	WarehouseId   int `xorm:"INTEGER"`
	SubdistrictId int `xorm:"INTEGER"`
	Standard      int `xorm:"not null default 500 INTEGER"`
	FreeStandard  int `xorm:"not null default 1000 INTEGER"`
}

type DeliveryType struct {
	Id                  int    `xorm:"not null pk autoincr INTEGER"`
	Name                string `xorm:"not null default '''::character varying' VARCHAR(10)"`
	TicketPrintTime     int    `xorm:"not null default 0 INTEGER"`
	DeliveryDescription string `xorm:"not null default '''::character varying' VARCHAR(255)"`
}

type Stock struct {
	Id             int     `xorm:"not null pk autoincr INTEGER"`
	CommodityId    int     `xorm:"not null INTEGER"`
	WarehouseId    int     `xorm:"not null INTEGER"`
	Amount         float64 `xorm:"not null default 0.0 DOUBLE"`
	Onsale         bool    `xorm:"not null default false BOOL"`
	Minimum        float64 `xorm:"not null default 0 DOUBLE"`
	StandardAmount float64 `xorm:"not null default 0 DOUBLE"`
	Recommended    int     `xorm:"not null default 1 SMALLINT"`
	Price          int     `xorm:"not null default 0 INTEGER"`
	PriceOnsale    int     `xorm:"not null default 0 INTEGER"`
	OnlineSale     bool    `xorm:"not null default false BOOL"`
}

type StockingItem struct {
	Id            int       `xorm:"not null pk autoincr INTEGER"`
	ProduceTime   time.Time `xorm:"not null TIMESTAMPZ"`
	Unit          string    `xorm:"not null default '''::character varying' VARCHAR(4)"`
	CommodityId   int       `xorm:"not null INTEGER"`
	StockingPrice int       `xorm:"not null default 100000 INTEGER"`
	StockingId    int       `xorm:"not null INTEGER"`
	Memo          string    `xorm:"not null default '''::character varying' VARCHAR(50)"`
	MountApply    float64   `xorm:"not null default 0 DOUBLE"`
	MountReceive  float64   `xorm:"not null default 0 DOUBLE"`
	PriceOnsale   int       `xorm:"not null default 100000 INTEGER"`
}

type Stocking struct {
	Id          int       `xorm:"not null pk autoincr INTEGER"`
	Status      int       `xorm:"not null default 1 SMALLINT"`
	MemoOfApply string    `xorm:"not null default '''::character varying' VARCHAR(500)"`
	TicketCode  string    `xorm:"not null default '''::character varying' VARCHAR(20)"`
	Created     time.Time `xorm:"not null TIMESTAMPZ"`
	Updated     time.Time `xorm:"not null TIMESTAMPZ"`
	WarehouseId int       `xorm:"not null INTEGER"`
	ApplicantId int       `xorm:"not null INTEGER"`
	CheckedById int       `xorm:"not null INTEGER"`
	ReceiverId  int       `xorm:"not null INTEGER"`
	BuyerId     int       `xorm:"not null INTEGER"`
}

type StockTransfer struct {
	Id             int       `xorm:"not null pk autoincr INTEGER"`
	TicketCode     string    `xorm:"not null default '''::character varying' VARCHAR(20)"`
	Status         int       `xorm:"not null default 1 SMALLINT"`
	InMemo         string    `xorm:"not null default '''::character varying' VARCHAR(300)"`
	OutMemo        string    `xorm:"not null default '''::character varying' VARCHAR(300)"`
	Created        time.Time `xorm:"not null TIMESTAMPZ"`
	Updated        time.Time `xorm:"not null TIMESTAMPZ"`
	WarehouseOutId int       `xorm:"not null INTEGER"`
	WarehouseInId  int       `xorm:"not null INTEGER"`
	HandlerOutId   int       `xorm:"not null INTEGER"`
	HandlerInId    int       `xorm:"not null INTEGER"`
}

type Supplier struct {
	Id          int    `xorm:"not null pk autoincr INTEGER"`
	Name        string `xorm:"not null default '''::character varying' unique VARCHAR(60)"`
	ContactInfo string `xorm:"not null default '''::character varying' VARCHAR(200)"`
	Address     string `xorm:"not null default '''::character varying' VARCHAR(100)"`
	Phone       string `xorm:"not null default '''::character varying' VARCHAR(50)"`
	Fax         string `xorm:"not null default '''::character varying' VARCHAR(30)"`
	Memo        string `xorm:"not null default '''::character varying' VARCHAR(500)"`
}

type StockTransferItem struct {
	Id              int     `xorm:"not null pk autoincr INTEGER"`
	CommodityId     int     `xorm:"not null INTEGER"`
	Amount          float64 `xorm:"not null default 0 DOUBLE"`
	StockTransferId int     `xorm:"not null INTEGER"`
}

type Order struct {
	Id             int       `xorm:"not null pk autoincr INTEGER"`
	Code           string    `xorm:"not null default '''::character varying' VARCHAR(30)"`
	OutOfPocket    int       `xorm:"not null default 0 INTEGER"`
	CommodityCount int       `xorm:"not null default 0 INTEGER"`
	Status         int       `xorm:"not null default 1 SMALLINT"`
	Created        time.Time `xorm:"not null TIMESTAMPZ"`
	Updated        time.Time `xorm:"not null TIMESTAMPZ"`
	WarehouseId    int       `xorm:"not null INTEGER"`
	Name           string    `xorm:"not null default '''::character varying' VARCHAR(20)"`
	Phone          string    `xorm:"not null default '''::character varying' VARCHAR(20)"`
	Address        string    `xorm:"not null default '''::character varying' VARCHAR(60)"`
	Gender         int       `xorm:"not null default 0 SMALLINT"`
	HandlerId      int       `xorm:"not null INTEGER"`
	DeliveryTypeId int       `xorm:"not null INTEGER"`
	DemandTime     int       `xorm:"not null default 600 INTEGER"`
	SubdistrictId  int       `xorm:"not null INTEGER"`
	TotalPrice     int       `xorm:"not null default 100000 INTEGER"`
	DeliveryFee    int       `xorm:"not null default 0 INTEGER"`
	MergedOrderId  int       `xorm:"not null INTEGER"`
}

type OrderDetail struct {
	Id            int     `xorm:"not null pk autoincr INTEGER"`
	OrderId       int     `xorm:"not null INTEGER"`
	CommodityId   int     `xorm:"not null INTEGER"`
	Amount        float64 `xorm:"not null default 0 DOUBLE"`
	PriceOnsale   int     `xorm:"not null default 10000 INTEGER"`
	Unit          string  `xorm:" VARCHAR(4)"`
	Specification string  `xorm:" VARCHAR(20)"`
	Memo          string  `xorm:"VARCHAR(300)"`      // 服务详情
	DeliveryTimes int     `xorm:"default 1 INTEGER"` // 送货次数
}

type MergedOrder struct {
	Id      int `xorm:"not null pk autoincr INTEGER"`
	UserId  int `xorm:"not null INTEGER"`
	OrderId int `xorm:"not null INTEGER"`
}

type Bookmark struct {
	Id          int `xorm:"not null pk autoincr INTEGER"`
	CommodityId int `xorm:"not null INTEGER"`
	UserId      int `xorm:"not null INTEGER"`
}
